package com.ruoyi.project.newhope.audio.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.newhope.audio.domain.NewHopeAudio;
import com.ruoyi.project.newhope.audio.service.INewHopeAudioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 音频Controller
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
@Controller
@RequestMapping("/api/newhope/audio")
public class NewHopeAudioController extends BaseController
{

    @Autowired
    private INewHopeAudioService newHopeAudioService;

    /**
     * 查询音频列表
     */
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewHopeAudio newHopeAudio)
    {
        startPage();
        List<NewHopeAudio> list = newHopeAudioService.selectNewHopeAudioList(newHopeAudio);
        return getDataTable(list);
    }

    /**
     * 查询音频列表
     */
    @GetMapping("/getAll")
    @ResponseBody
    public AjaxResult getAll(NewHopeAudio newHopeAudio)
    {
        List<NewHopeAudio> list = newHopeAudioService.selectNewHopeAudioList(newHopeAudio);
        return AjaxResult.success(list);
    }

    /**
     * 新增保存音频
     */
    @Log(title = "音频", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody NewHopeAudio newHopeAudio)
    {
        return toAjax(newHopeAudioService.insertNewHopeAudio(newHopeAudio));
    }

    /**
     * 修改音频
     */
    @GetMapping("/edit/{id}")
    @ResponseBody
    public NewHopeAudio edit(@PathVariable("id") Long id)
    {
        NewHopeAudio newHopeAudio = newHopeAudioService.selectNewHopeAudioById(id);
        return newHopeAudio;
    }

    /**
     * 修改保存音频
     */
    @Log(title = "音频", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody NewHopeAudio newHopeAudio)
    {
        return toAjax(newHopeAudioService.updateNewHopeAudio(newHopeAudio));
    }

    /**
     * 删除音频
     */
    @Log(title = "音频", businessType = BusinessType.DELETE)
    @GetMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String id)
    {
        return toAjax(newHopeAudioService.deleteNewHopeAudioByIds(id));
    }
}
